//
//  AlertRowsView.swift
//  loveHHEveryDay
//
//  Created by yw on 2025/4/21.
//

import UIKit

struct RowsModel:Identifiable {
    var id:String = UUID().uuidString
    var name:String = ""
    var value:String = ""
    var index:Int = 0
}


class AlertRowsView: UIView {
    let list:[RowsModel] = [
        RowsModel(name: "从相册选择", value: "2",index: 0),
        RowsModel(name: "拍照", value: "1",index: 1),
        RowsModel(name: "取消", value: "2",index: 2),
    ]
    
    var clickBlock:(_:(_ tag:Int)->Void)?
    
    init(frame: CGRect,clickBlock:(_:(_ tag:Int)->Void)) {
        super.init(frame: frame)
        self.clickBlock = clickBlock
        let h = 60
        for item in list {
            let btn = UIButton(frame: CGRectMake(0, CGFloat(h * item.index), kScreenWidth, 60))
            btn.setTitle(item.name, for: .normal)
            btn.setTitleColor(UIColor(named: "color_text_main"), for: .normal)
            btn.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: .bold)
            btn.tag = item.index
            btn.addTarget(self, action: #selector(rowsClick(button:)), for: .touchUpInside)
            self.addSubview(btn)
        }
        
        self.backgroundColor = UIColor(named: "color_bg")
        self.layer.cornerRadius = 20
        self.clipsToBounds = true
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc func rowsClick(button:UIButton) {
        let generator = UIImpactFeedbackGenerator(style: .light)
        generator.prepare()
        generator.impactOccurred()
        self.hideToView()
        self.clickBlock?(button.tag)
    }
    
    deinit {
        DPrint("AlertRowsView Die")
    }
    


}
